@namespace DevToys.Blazor.Components.UIElements
@using DevToys.Api;
@inherits ComponentBase

<Button id="@UIButton.Id"
        IsVisible="@UIButton.IsVisible"
        IsEnabled="@UIButton.IsEnabled"
        HorizontalAlignment="@UIButton.HorizontalAlignment"
        VerticalAlignment="@UIButton.VerticalAlignment"
        Appearance="@((UIButton.IsAccent ? ButtonAppearance.Accent : UIButton.IsHyperlink ? ButtonAppearance.Hyperlink : ButtonAppearance.Neutral))"
        @onclick=OnButtonClickAsync>
    @{
        var glyph = UIButton is IUIUtf32IconProvider provider ? provider.Utf32IconGlyph : UIButton.IconGlyph;
        if (!string.IsNullOrWhiteSpace(UIButton.IconFontName) && glyph != 0)
        {
            <StackPanel Orientiation="UIOrientation.Horizontal" Spacing="4">
                <FontIcon Glyph="@glyph"
                          FontFamily="@UIButton.IconFontName"
                          Height="16"
                          Width="16" />
                @if (!string.IsNullOrEmpty(UIButton?.Text))
                {
                    <TextBlock Text="@UIButton?.Text" NoWrap="true" />
                }
            </StackPanel>
        }
        else
        {
            <TextBlock Text="@UIButton?.Text" NoWrap="true" />
        }
    }
</Button>